package test;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class MyFrame3 extends JFrame {
    public MyFrame3() {
        setTitle("Background Image Example");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(400, 300);

        JPanel mainPanel = new JPanel(new GridBagLayout());

        // Replace with your desired image file name or path
        ImageIcon imageIcon = new ImageIcon("C:\\Users\\hahon\\Desktop\\课设\\项目\\untitled1\\src\\main\\java\\机票预定系统背景图.jpg");
        JLabel backgroundLabel = new JLabel(imageIcon);

        // Create constraints for the background label
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0; // Position in grid
        gbc.gridy = 0;
        gbc.weightx = 1.0; // Expand horizontally to fill the cell
        gbc.weighty = 1.0; // Expand vertically to fill the cell
        gbc.fill = GridBagConstraints.BOTH; // Fill the cell in both directions

        mainPanel.add(backgroundLabel, gbc);

        // Add other components to the mainPanel using GridBagConstraints

        add(mainPanel);
    }

    public static void main(String[] args) {
        MyFrame3 frame = new MyFrame3();
        frame.setVisible(true);
    }
}
